package controllers

import (
	"github.com/astaxie/beego"
)

type BaseController struct {
	beego.Controller
}
type Response struct {
	Code    int         `json:"code"`
	Data    interface{} `json:"data"`
	Message string      `json:"message"`
}

const (
	API_OK     = 200
	CODE_OK    = 0
	CODE_ERROR = -1
)

//请求回复 基本
func (b *BaseController) ApiView(StatusCode int, Code int, Data interface{}, Message string) {
	resp := Response{Code: Code, Data: Data, Message: Message}
	b.Ctx.Output.SetStatus(StatusCode)
	b.Data["json"] = &resp
	b.ServeJSON()
}

//请求回复  成功
func (b *BaseController) ApiViewOk(Data interface{}) {
	resp := Response{Code: CODE_OK, Data: Data, Message: ""}
	b.Ctx.Output.SetStatus(API_OK)
	b.Data["json"] = &resp
	b.ServeJSON()
}

//请求回复  失败
func (b *BaseController) ApiViewError(StatusCode int) {
	resp := Response{Code: CODE_ERROR, Data: "", Message: ""}
	b.Ctx.Output.SetStatus(StatusCode)
	b.Data["json"] = &resp
	b.ServeJSON()
}
